//
//  SLPagerReusePool.h
//  SLPagerView
//
//  Created by l.t.zero on 2022/1/7.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@protocol SLPagerItem <NSObject>

@optional
- (Class)classForCell;///显示数据所对应的cell class

@end

@protocol SLPagerReusePoolDelegate <NSObject>

- (void)sl_pagerPrefetchAtIndexPath:(NSIndexPath *)indexPath;

@optional
- (void)sl_pagerPrefetchDidCancelled:(NSIndexPath *)indexPath;

@end

@interface SLPagerReusePool : NSObject

@property (nonatomic) NSUInteger depth;//预加载深度
@property (nonatomic) CGRect preferredFrame;//复用对象默认frame
@property (atomic) BOOL disablePrefetched;//复用对象默认frame
@property (nonatomic) BOOL enableInfinateScroll;//复用对象默认frame

@property (nonatomic, weak) id<SLPagerReusePoolDelegate> delegate;//预加载深度

- (void)registerClass:(nullable Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier;
- (__kindof UIView *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath;

- (UIView *)clearReuseFor:(NSIndexPath *)indexPath;
- (UIView *)reuseViewFor:(NSIndexPath *)indexPath;
- (NSIndexPath *)indexPathForReuseView:(UIView *)view;

- (void)prefetchByVisibleIndexPaths:(NSArray<NSIndexPath *> *)ips limited:(NSInteger)total;
- (BOOL)isPrefetchedFor:(NSIndexPath *)indexPath;
- (void)prefetchedFor:(NSIndexPath *)indexPath;

- (void)invaliteAllReuse;
- (void)clearPrefetchedFor:(NSIndexPath *)indexPath;
- (void)clearPrefetchedFrom:(NSIndexPath *)indexPath;
- (void)clearAllPrefetched;
- (void)clear;

- (void)clearInUse:(UIView *)view;
- (void)reuse:(UIView *)view;

///前面追加数据，需更新数据索引
- (void)updateIndexPath:(NSIndexPath* (^)(NSIndexPath *indexPath))block;

@end

NS_ASSUME_NONNULL_END
